 // 1------获取商品的id
      //获取url中 问号后面的内容--搜索字段
      //   ?id=732951
      console.log(location.search);
      //a=2&b=2&ddw=2 转为对象
      var obj = new URLSearchParams(location.search);
      console.log(obj);
      //   732951
      //   通过get方法 获取对应的参数的值
      var pid = obj.get("id");
      console.log("pid"+pid);

      //   2---根据商品id获取商品详情 ，调用接口
      let url = "http://jx.xuzhixiang.top/ap/api/detail.php";
      axios.get(url, { params: { id: pid } }).then((r) => {
        console.log(r.data);
        //商品对象
        var pObj = r.data.data;
        console.log(pObj);

        // 拼成商品详情给 div
        let str = ` 
            <div class="pro_item">
                <div class="photo">
                    <img src="${pObj.pimg}" alt="">
                </div>
                <div class="info">
                    <div id="pname">${pObj.pname}</div>
                    <div id="pprice">
                        <label for="">销售价格</label>
                        <span>￥${pObj.pprice}</span>
                    </div>
                    <div id="pdesc">${pObj.pdesc}</div>
                    <input type="number" value='1' min="1" class="pnum">
                    <button onclick="addCartHandle()">加入购物车</button>
                    
                </div>
            </div>
        `;
        document.querySelector(".pro_list").innerHTML = str;
      });

      //   5-1
      //   加入购物车事件
      function addCartHandle() {
        console.log("点击了加入购物车");
        // 5-2 发起请求
        let uid = localStorage.getItem("uid");
        console.log("uid"+uid);
        let pnum = document.querySelector(".pnum").value;
        let url = "http://jx.xuzhixiang.top/ap/api/add-product.php";
        axios
          .get(url, {
            params: {
              uid,
              pid,
              pnum,
            },
          })
          .then((r) => {
            //加入购物车成功
            console.log(r.data);
          });
      }